//
//  OrderDetialCellTableViewCell.m
//  ForestPack
//
//  Created by 骆锴 on 2018/7/26.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "OrderDetialCell.h"
#import "AddressManagerModel.h"

@interface OrderDetialCell ()

@property (nonatomic, strong) UIImageView *head;
@property (nonatomic, strong) UILabel *Consignee;
@property (nonatomic, strong) UILabel *address;
@end

@implementation OrderDetialCell

+ (OrderDetialCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"orderDetialCell";
    OrderDetialCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[OrderDetialCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

-(void)createSubView{
    _head = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(64), ScreenX375(64))];
    _head.image = [UIImage imageNamed:@"我的"];
    _head.clipsToBounds = YES;
    _head.layer.cornerRadius = 32.0;
    [self addSubview: _head];
    
    _Consignee =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(93.5), ScreenX375(21), ScreenX375(230), ScreenX375(14))];
    _Consignee.font = Kfont(14);
    _Consignee.textColor = REXADECIMALCOLOR(@"#333333");
    _Consignee.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_Consignee];
    
    _address =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(93.5), ScreenX375(43), ScreenX375(230), ScreenX375(30))];
    _address.numberOfLines = 2;
    _address.font = Kfont(12);
    _address.textColor = REXADECIMALCOLOR(@"#999999");
    _address.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_address];
    
    UIButton *more =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(355), ScreenX375(41), ScreenX375(7), ScreenX375(12))];
    [more setBackgroundImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
    [self addSubview:more];
}

-(void)initWithModel:(AddressManagerDataModel *)model{
    _Consignee.text = [NSString stringWithFormat:@"收货人:%@             %@",model.consignee,model.telephone];
    _address.text = [NSString stringWithFormat:@"【默认】%@%@%@%@",model.province,model.city,model.district,model.place];
}

@end

@interface ExpressMethodCell ()

@property (nonatomic, strong) UILabel *costvalue;
@property (nonatomic, strong) UILabel *deliverytime;

@end

@implementation ExpressMethodCell

+ (ExpressMethodCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"ExpressMethodCell";
    ExpressMethodCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ExpressMethodCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

-(void)createSubView{
    _specialcar =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(109), ScreenX375(30))];
    _specialcar.tag = 100;
    [_specialcar setTitle:@"专车" forState:UIControlStateNormal];
    [_specialcar setTitleColor:REXADECIMALCOLOR(@"#999999") forState:UIControlStateNormal];
    [_specialcar setTitleColor:ThemeColor forState:UIControlStateSelected];
    [_specialcar addTarget:self action:@selector(selectClicked) forControlEvents:UIControlEventTouchUpInside];
    _specialcar.layer.cornerRadius = 15.0;
    _specialcar.layer.borderWidth = 0.5;
    _specialcar.selected = YES;
    _specialcar.layer.borderColor = ThemeColor.CGColor;
    [self addSubview:_specialcar];
    
    _express =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(132), ScreenX375(15), ScreenX375(109), ScreenX375(30))];
    _express.tag = 101;
    [_express setTitle:@"快递" forState:UIControlStateNormal];
    [_express setTitleColor:REXADECIMALCOLOR(@"#999999") forState:UIControlStateNormal];
    [_express setTitleColor:ThemeColor forState:UIControlStateSelected];
    [_express addTarget:self action:@selector(selectClicked) forControlEvents:UIControlEventTouchUpInside];
    _express.layer.cornerRadius = 15.0;
    _express.layer.borderWidth = 0.5;
    _express.selected = NO;
    _express.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
    [self addSubview:_express];
    
    UIImageView *point1 = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(58.5), ScreenX375(5), ScreenX375(5))];
    point1.image = [UIImage imageNamed:@"红点"];
    [self addSubview: point1];
    
    UILabel *cost =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(28.5), ScreenX375(55), ScreenX375(40), ScreenX375(12))];
    cost.text = @"费用：";
    cost.font = Kfont(12);
    cost.textColor = REXADECIMALCOLOR(@"#333333");
    cost.textAlignment = NSTextAlignmentLeft;
    [self addSubview:cost];
    
    UIImageView *point2 = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(89.5), ScreenX375(5), ScreenX375(5))];
    point2.image = [UIImage imageNamed:@"红点"];
    [self addSubview: point2];
    
    _costvalue =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(68.5), ScreenX375(55), ScreenX375(100), ScreenX375(12))];
    _costvalue.text = @"￥50.00";
    _costvalue.font = Kfont(12);
    _costvalue.textColor = ThemeColor;
    _costvalue.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_costvalue];
    
    _deliverytime =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(28.5), ScreenX375(87), ScreenX375(200), ScreenX375(12))];
    _deliverytime.text = @"预计发货时间：2018年06月01日";
    _deliverytime.font = Kfont(12);
    _deliverytime.textColor = REXADECIMALCOLOR(@"#333333");
    _deliverytime.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_deliverytime];
    
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(76.5), ScreenX375(349), ScreenX375(1))];
    UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"虚线"]];
    [line setBackgroundColor:color];
    [self addSubview:line];
    
    UILabel *warming =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(28), ScreenX375(107), ScreenX375(200), ScreenX375(10))];
    warming.text = @"若您对发货有疑问，请联系客服帮您解决";
    warming.font = Kfont(10);
    warming.textColor = ThemeColor;
    warming.textAlignment = NSTextAlignmentLeft;
    [self addSubview:warming];

}

-(void)selectClicked
{
    if (_selectClick) {
        _selectClick();
    }
}

-(void)btnDidClick:(UIButton*)sender{
    for (int i = 0; i < 2; i++) {
        UIButton *btn = (UIButton *)[[sender superview]viewWithTag:100 + i];
        [btn setSelected:NO];
    }
    
    UIButton *button = (UIButton *)sender;
    [button setSelected:YES];
    if (button.selected == YES) {
        button.layer.borderColor = ThemeColor.CGColor;
    }
    
    for (int i = 0; i < 2; i++) {
        UIButton *btn = (UIButton *)[[sender superview]viewWithTag:100 + i];
        if (btn.selected == NO) {
            btn.layer.borderColor = btn.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
        }
    }
}

@end

@interface OtherCell ()<UITextViewDelegate>

@property (nonatomic, strong) UILabel *Coupon;

@end

@implementation OtherCell

+ (OtherCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"otherCell";
    OtherCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[OtherCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

-(void)createSubView{
    UILabel *Coupon =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(8), ScreenX375(100), ScreenX375(14))];
    Coupon.text = @"使用优惠券";
    Coupon.font = Kfont(14);
    Coupon.textColor = REXADECIMALCOLOR(@"#333333");
    Coupon.textAlignment = NSTextAlignmentLeft;
    [self addSubview:Coupon];
    
    _Nocoupon = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(32), ScreenX375(160), ScreenX375(34))];
    _Nocoupon.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [_Nocoupon setTitle:@"  不使用优惠劵" forState:UIControlStateNormal];
    [_Nocoupon setTitleColor:REXADECIMALCOLOR(@"#999999") forState:UIControlStateNormal];
    _Nocoupon.titleLabel.font = Kfont(12);
    [_Nocoupon setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [_Nocoupon setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
    _Nocoupon.selected = YES;
    [_Nocoupon addTarget:self action:@selector(isCouponsClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_Nocoupon];
    
    UILabel *Remark =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(66.5), ScreenX375(100), ScreenX375(14))];
    Remark.text = @"备注";
    Remark.font = Kfont(14);
    Remark.textColor = REXADECIMALCOLOR(@"#333333");
    Remark.textAlignment = NSTextAlignmentLeft;
    [self addSubview:Remark];
    
    UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
    UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
    NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
    [bar setItems:buttonsArray];
    
    _remark = [[UITextView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(90.5), ScreenX375(349), ScreenX375(68))];
    _remark.textColor = REXADECIMALCOLOR(@"#999999");
    _remark.text = @"请输入您的额外需求";
    _remark.delegate = self;
    _remark.textAlignment = NSTextAlignmentLeft;
    _remark.font = Kfont(12.0);
    _remark.layer.cornerRadius = 5.0;
    _remark.layer.borderWidth = 0.5;
    _remark.inputAccessoryView = bar;
    _remark.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
    [self addSubview:_remark];
    
}

-(void)isCouponsClicked{
    if (_isCouponsClick) {
        _isCouponsClick();
    }
}

-(void)selectType:(UIButton *)button{
    if (button.selected == YES) {
        button.selected = NO;
    }else
        button.selected = YES;
}

-(void)textViewDidBeginEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@"请输入您的额外需求"]) {
        textView.textColor = [UIColor blackColor];
        textView.text = @"";
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    if (textView.text.length < 1) {
        textView.textColor = REXADECIMALCOLOR(@"#999999");
        textView.text = @"请输入您的额外需求";
    }
}

-(void)textViewDidChange:(UITextView *)textView{
    self.block(textView.text);
}

-(void)resignKey{
    [_remark resignFirstResponder];
}
@end

@interface ProductInformationCell ()

@property (nonatomic, strong) UILabel *factory;
@property (nonatomic, strong) UILabel *paperboxmodel;
@property (nonatomic, strong) UILabel *material;
@property (nonatomic, strong) UILabel *surface;
@property (nonatomic, strong) UILabel *boxmethod;
@property (nonatomic, strong) UILabel *packingmethod;
@property (nonatomic, strong) UILabel *intersize;
@property (nonatomic, strong) UILabel *outsize;

@end

@implementation ProductInformationCell

+(ProductInformationCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"ProductInformationCell";
    ProductInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ProductInformationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    return cell;
}

-(void)createSubView{
    NSArray *labely = [[NSArray alloc] initWithObjects:@"15",@"15",@"43",@"43",@"72.5",@"72.5",@"98.5",@"98.5", nil];
    NSArray *labelvalue = [[NSArray alloc] initWithObjects:@"发货厂区：",@"纸箱类型：",@"材质楞型：",@"表面处理：",@"成箱方式：",@"打包方式：",@"内径尺寸：",@"外径尺寸：", nil];
    for (int i = 0 ;i < labely.count ; i++) {
        if (i % 2 == 0) {
            UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375([[labely objectAtIndex:i] integerValue]), ScreenX375(70), ScreenX375(12.5))];
            label.text = [labelvalue objectAtIndex:i];
            label.font = Kfont(12);
            label.textColor = REXADECIMALCOLOR(@"#999999");
            label.textAlignment = NSTextAlignmentLeft;
            [self addSubview:label];
        }else{
            UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(195.5), ScreenX375([[labely objectAtIndex:i] integerValue]), ScreenX375(70), ScreenX375(12.5))];
            label.text = [labelvalue objectAtIndex:i];
            label.font = Kfont(12);
            label.textColor = REXADECIMALCOLOR(@"#999999");
            label.textAlignment = NSTextAlignmentLeft;
            [self addSubview:label];
        }
    }
    
    _factory =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(75), ScreenX375(15), ScreenX375(70), ScreenX375(12.5))];
    _factory.font = Kfont(12);
    _factory.textColor = REXADECIMALCOLOR(@"#333333");
    _factory.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_factory];
    
    _paperboxmodel =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(260), ScreenX375(15), ScreenX375(70), ScreenX375(12.5))];
    _paperboxmodel.font = Kfont(12);
    _paperboxmodel.textColor = REXADECIMALCOLOR(@"#333333");
    _paperboxmodel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_paperboxmodel];
    
    _material =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(75), ScreenX375(43), ScreenX375(70), ScreenX375(12.5))];
    _material.font = Kfont(12);
    _material.textColor = REXADECIMALCOLOR(@"#333333");
    _material.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_material];
    
    _surface =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(260), ScreenX375(43), ScreenX375(70), ScreenX375(12.5))];
    _surface.font = Kfont(12);
    _surface.textColor = REXADECIMALCOLOR(@"#333333");
    _surface.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_surface];
    
    _boxmethod =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(75), ScreenX375(71.5), ScreenX375(70), ScreenX375(12.5))];
    _boxmethod.font = Kfont(12);
    _boxmethod.textColor = REXADECIMALCOLOR(@"#333333");
    _boxmethod.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_boxmethod];
    
    _packingmethod =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(260), ScreenX375(71.5), ScreenX375(70), ScreenX375(12.5))];
    _packingmethod.font = Kfont(12);
    _packingmethod.textColor = REXADECIMALCOLOR(@"#333333");
    _packingmethod.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_packingmethod];
    
    _intersize =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(75), ScreenX375(98.5), ScreenX375(100), ScreenX375(12.5))];
    _intersize.font = Kfont(12);
    _intersize.textColor = REXADECIMALCOLOR(@"#333333");
    _intersize.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_intersize];
    
    _outsize =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(260), ScreenX375(98.5), ScreenX375(100), ScreenX375(12.5))];
    _outsize.font = Kfont(12);
    _outsize.textColor = REXADECIMALCOLOR(@"#333333");
    _outsize.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_outsize];
}

-(void)initWithArray:(NSMutableArray *)dataArray{
    NSString *factory = [NSString stringWithFormat:@"%@",kNSUDefaultReadKey(@"Factory")];
    _factory.text = factory;
    _paperboxmodel.text = [dataArray objectAtIndex:1];
    _material.text = [dataArray objectAtIndex:2];
    _surface.text = [dataArray objectAtIndex:3];
    _boxmethod.text = [dataArray objectAtIndex:4];
    _packingmethod.text = [dataArray objectAtIndex:5];
    _intersize.text = [dataArray objectAtIndex:6];
    _outsize.text = [dataArray objectAtIndex:7];
}

@end

